<?php 
  require(dirname(__FILE__).'/global.php');
  require(ROOT.'/admin/isLogin.php');
  require(ROOT.'/include/xml.class.php'); 
  
  $submit = $_POST['submit'];
  $xmlPath = ROOT.'/common.xml';
  $xml = new SimpleXMLUtil($xmlPath);
  if(isset($submit))
  {
      $siteName = $_POST['siteName'];
      $siteURL = $_POST['siteURL'];
      if(!DataConverter::isURL($siteURL))
      {
          $smarty->assign('tip','域名不正确');
      }
      else
      {
          $siteICP = $_POST['siteICP'];
          $isAllowCreateBar = $_POST['isAllowCreateBar'];
          $isAllowCreateBar = empty($isAllowCreateBar) ? 'y' : $isAllowCreateBar;
          $attachSize = $_POST['attachSize'];
          if(!DataConverter::isAttachSize($attachSize))
          {
              $smarty->assign('tip','附件尺寸大小设置有误');
          }
          else
          {
              $isClosed = $_POST['isClosed'];
              $isClosed = empty($isClosed) ? 'n' : $isClosed;
              $closeReason = $_POST['closeReason'];
              $thirdCount = addslashes($_POST['thirdCount']);
              
              $xml->setElementValue('Name',$siteName);
              $xml->setElementValue('URL',$siteURL);
              $xml->setElementValue('ICP',$siteICP);
              $xml->setElementValue('CreateBar',$isAllowCreateBar);
              $xml->setElementValue('AttachSize',$attachSize);
              $xml->setElementValue('Close',$isClosed);
              $xml->setElementValue('Reason',$closeReason);
              $xml->setElementValue('Statistics',$thirdCount);
              $xml->save();
                                           
              $smarty->assign('tip','更新成功');
          }
      } 
  }
  $siteName = $xml->getElementValue("Name");
  $siteURL = $xml->getElementValue("URL");
  $siteICP = $xml->getElementValue("ICP");
  $isAllowCreateBar = $xml->getElementValue("CreateBar") ? $xml->getElementValue("CreateBar") : 'y';
  $attachSize = $xml->getElementValue("AttachSize");
  $isClosed = $xml->getElementValue("Close") ? $xml->getElementValue("Close") : 'n' ;  
  $closeReason = $xml->getElementValue("Reason"); 
  $statistics = $xml->getElementValue("Statistics");
   
  $smarty->assign('siteName',$siteName);
  $smarty->assign('siteURL',$siteURL);
  $smarty->assign('siteICP',$siteICP);
  $smarty->assign('isAllowCreateBar',$isAllowCreateBar);
  $smarty->assign('attachSize',$attachSize);
  $smarty->assign('isClosed',$isClosed);
  $smarty->assign('closeReason',$closeReason);
  $smarty->assign('thirdCount',$statistics);
  $smarty->display('basic.html');
  $db->close();
?>
